#include<iostream>
#include<algorithm>
using namespace std;

struct metal
{
	double n;
	double v;
	double value;//n重量 v价值 value单位价值
} m[105];

bool cmp(metal a, metal b) 	//按单位价值升序
{
	return a.value < b.value;
}

int main()
{
	int k;
	cin >> k;			//k组
	for (int i = 0; i < k; i++)
	{
		int w, s;	//w承重 s种类
		cin >> w >> s;
		for (int j = 1; j <= s; j++)
		{
			cin >> m[j].n >> m[j].v;
			m[j].value = m[j].v / m[j].n; //计算单位价值
		}
		sort(m + 1, m + s + 1, cmp);
		double t = 0;	//总价值
		for (int k = s; k >= 1; k--)
		{
			if (m[k].n <= w) 	//如果金属重量小于口袋上限
			{
				t += m[k].v;
				w -= m[k].n;
			}
			else
			{
				t += m[k].value * w;
				break;
			}
		}
		printf("%.2lf\n", t);
	}
	return 0;
}


